<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item label="病案号" prop="medicareNo">
            <el-input
              v-model="queryParams.medicareNo"
              placeholder="请输入病案号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="患者姓名" prop="patientName">
            <el-input
              v-model="queryParams.patientName"
              placeholder="请输入患者姓名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="科室/病区" prop="deptId">
            <!-- <el-input
              v-model="queryParams.deptId"
              placeholder="请输入科室/病区"
              clearable
              @keyup.enter.native="handleQuery"
            /> -->
            <treeselect
              style="width: 215px"
              v-model="queryParams.deptId"
              :options="deptOptions"
              :show-count="true"
              placeholder="请选择科室/病区"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <!-- <el-form-item label="ID号" prop="patientNo">
            <el-input
              v-model="queryParams.patientNo"
              placeholder="请输入ID号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item> -->
          <el-form-item label="监护分级" prop="guardianLevel">
            <!-- <el-input
              v-model="queryParams.guardianLevel"
              placeholder="请输入监护分级"
              clearable
              @keyup.enter.native="handleQuery"
            /> -->
            <el-select
              v-model="queryParams.guardianLevel"
              placeholder="请输入监护分级"
              clearable
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in guardianLevel"
                :key="index"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- <el-form-item label="住院医师" prop="doctorId">
          <el-input
            v-model="queryParams.doctorId"
            placeholder="请输入临床药师"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
      <el-row>
        <el-col :span="12">
          <el-form-item label="出院日期">
            <el-date-picker
              style="width: 600px !important"
              v-model="time"
              type="daterange"
              range-separator="至"
              start-placeholder="请选择出院时间起始日期"
              end-placeholder="请选择出院时间结束日期"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
              @change="handletime"
              clearable
            >
            </el-date-picker>
            <!-- <el-date-picker
              clearable
              v-model="queryParams.admissionDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择入院时间"
            >
            </el-date-picker> -->
          </el-form-item>
          <!-- <el-form-item label="床号" prop="bedNo">
            <el-input
              v-model="queryParams.bedNo"
              placeholder="请输入床号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item> -->
        </el-col>
        <!-- <el-form-item label="第一诊断" prop="firstDiagnose">
          <el-input
            v-model="queryParams.firstDiagnose"
            placeholder="请输入第一诊断"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <!-- <el-col :span="6">
          <el-form-item label="住院医师" prop="doctorName">
            <el-input
              v-model="queryParams.doctorName"
              placeholder="请输入临床药师"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col> -->
        <el-col :span="6">
          <el-form-item label="住院状态" prop="patientState">
            <!-- <el-input
              v-model="queryParams.patientState"
              placeholder="请输入住院状态"
              clearable
              @keyup.enter.native="handleQuery"
            /> -->
            <el-select
              v-model="queryParams.patientState"
              placeholder="请输入住院状态"
              clearable
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in patientState"
                :key="index"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- <el-form-item label="年龄" prop="patientAge">
          <el-input
            v-model="queryParams.patientAge"
            placeholder="请输入年龄"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="职业" prop="patientProfession">
          <el-input
            v-model="queryParams.patientProfession"
            placeholder="请输入职业"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="民族" prop="nation">
          <el-input
            v-model="queryParams.nation"
            placeholder="请输入民族"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="身高" prop="patientHeight">
          <el-input
            v-model="queryParams.patientHeight"
            placeholder="请输入身高"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="体重" prop="patientWeight">
          <el-input
            v-model="queryParams.patientWeight"
            placeholder="请输入体重"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="BMI" prop="patientBmi">
          <el-input
            v-model="queryParams.patientBmi"
            placeholder="请输入BMI"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="联系方式" prop="phoneNo">
          <el-input
            v-model="queryParams.phoneNo"
            placeholder="请输入联系方式"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="付费方式" prop="payWay">
          <el-input
            v-model="queryParams.payWay"
            placeholder="请输入付费方式"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="数据来源" prop="sourceInfo">
          <el-input
            v-model="queryParams.sourceInfo"
            placeholder="请输入数据来源"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-col :span="6" style="padding-left: 10px">
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['workstation:baseInfo:add']"
              >新增</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['workstation:baseInfo:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['workstation:baseInfo:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['workstation:baseInfo:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['workstation:baseInfo:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->

    <!-- <el-table
      v-if="0"
      v-loading="loading"
      :data="baseInfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="患者ID" align="center" prop="id" v-if="true" />
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="病案号" align="center" prop="medicalRecordNo" />
      <el-table-column label="ID号" align="center" prop="patientNo" />
      <el-table-column label="科室/病区" align="center" prop="deptId" />
      <el-table-column
        label="入院时间"
        align="center"
        prop="admissionDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.admissionDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="住院医师" align="center" prop="doctorId" />
      <el-table-column label="床号" align="center" prop="bedNo" />
      <el-table-column label="第一诊断" align="center" prop="firstDiagnose" />
      <el-table-column label="监护分级" align="center" prop="guardianLevel" />
      <el-table-column label="住院状态" align="center" prop="patientState" />
      <el-table-column label="患者性别" align="center" prop="patientSex" />
      <el-table-column label="年龄" align="center" prop="patientAge" />
      <el-table-column label="职业" align="center" prop="patientProfession" />
      <el-table-column label="民族" align="center" prop="nation" />
      <el-table-column label="身高" align="center" prop="patientHeight" />
      <el-table-column label="体重" align="center" prop="patientWeight" />
      <el-table-column label="BMI" align="center" prop="patientBmi" />
      <el-table-column label="联系方式" align="center" prop="phoneNo" />
      <el-table-column label="付费方式" align="center" prop="payWay" />
      <el-table-column label="数据来源" align="center" prop="sourceInfo" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['workstation:baseInfo:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['workstation:baseInfo:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table> -->

    <!-- 患者信息展示区 -->

    <div class="mainInfoBox">
      <el-row :gutter="10">
        <el-col :span="4.8" v-for="item in baseInfoList" :key="item.id">
          <!-- v-hasPermi="['workstation:baseInfo:query']" -->
          <div
            class="userBox"
            @click="toUseDetail(item)"
            :class="
              item.guardianLevel == 0
                ? 'one'
                : item.guardianLevel == 1
                ? 'two'
                : ''
            "
          >
            <div class="line pr20" style="justify-content: space-between">
              <span class="chuanghao">{{ item.medicalRecordNo }}</span>
              <span
                class="useStatus"
                :style="
                  item.patientState == '1'
                    ? 'background-color: rgba(245, 154, 35, 1)'
                    : ''
                "
                >{{ item.patientStateStr }}</span
              >
            </div>
            <div class="line">
              <span class="title">科室:</span
              ><span class="titleNum">{{ item.deptName }}</span>
            </div>
            <div class="line">
              <span class="title">患者姓名:</span
              ><span class="titleNum">{{ item.patientName }}</span>
            </div>
            <div class="line">
              <span class="title">年龄:</span>
              <span
                class="titleNum"
                style="
                  display: flex;
                  align-items: center;
                  font-family: 'PingFang SC, PingFang SC, sans-serif';
                "
              >
                <span v-if="item.patientAge">{{ item.patientAge }}岁</span>
                <span
                  v-if="item.patientMonth"
                  style="font-family: 'PingFang SC, PingFang SC, sans-serif';margin-left: 5px;"
                >
                  {{ item.patientMonth }}月</span
                >
              </span>
            </div>
            <div class="line">
              <span class="title">ID号:</span
              ><span class="titleNum">{{ item.patientNo }}</span>
            </div>
            <div class="line">
              <span class="title">病案号:</span
              ><span class="titleNum">{{ item.medicareNo }}</span>
            </div>
            <div class="line">
              <span class="title">住院医师:</span
              ><span class="titleNum">{{ item.doctorName }}</span>
            </div>
            <div class="line">
              <span class="title">入院时间:</span
              ><span class="titleNum">{{ item.admissionTime }}</span>
            </div>
            <div class="line">
              <span class="title">出院时间:</span
              ><span class="titleNum">{{ item.dischargeTime }}</span>
            </div>
            <div class="line">
              <span class="title">床号:</span
              ><span class="titleNum">{{ item.bedNo }}</span>
            </div>
            <div class="line">
              <span class="title">第一诊断:</span
              ><span class="titleNum line-2">{{ item.firstDiagnose }}</span>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>

    <!-- 患者信息展示区 -->

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改患者基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="85px"
        label-position="left"
      >
        <el-form-item label="患者姓名" prop="patientName">
          <el-input v-model="form.patientName" placeholder="请输入患者姓名" />
        </el-form-item>
        <!-- <el-form-item label="病案号" prop="medicalRecordNo">
          <el-input v-model="form.medicalRecordNo" placeholder="请输入病案号" />
        </el-form-item> -->
        <el-form-item label="ID号" prop="patientNo">
          <el-input v-model="form.patientNo" placeholder="请输入ID号" />
        </el-form-item>
        <el-form-item label="科室/病区" prop="deptId">
          <!-- <el-input v-model="form.deptId" placeholder="请输入科室/病区" /> -->
          <treeselect
            v-model="form.deptId"
            :options="deptOptions"
            :show-count="true"
            placeholder="请选择科室/病区"
          />
        </el-form-item>
        <el-form-item label="入院时间" prop="admissionTime">
          <el-date-picker
            clearable
            v-model="form.admissionTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择入院时间"
            :picker-options="setDisabled"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="住院医师" prop="doctorId">
          <!-- <el-input v-model="form.doctorId" placeholder="请输入临床药师" @focus="getDoctorList" /> -->
          <el-select
            v-model="form.doctorId"
            placeholder="请选择临床药师"
            clearable
            @change="handleDoctorName"
            :style="{ width: '100%' }"
          >
            <el-option
              v-for="(item, index) in DoctorList"
              :key="index"
              :label="item.nickName"
              :value="item.userId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="床号" prop="bedNo">
          <el-input v-model="form.bedNo" placeholder="请输入床号" />
        </el-form-item>
        <el-form-item label="第一诊断" prop="firstDiagnose">
          <el-input v-model="form.firstDiagnose" placeholder="请输入第一诊断" />
        </el-form-item>
        <!-- <el-form-item label="监护分级" prop="guardianLevel">
          <el-input v-model="form.guardianLevel" placeholder="请输入监护分级" />
        </el-form-item>
        <el-form-item label="住院状态" prop="patientState">
          <el-input v-model="form.patientState" placeholder="请输入住院状态" />
        </el-form-item>
        <el-form-item label="年龄" prop="patientAge">
          <el-input v-model="form.patientAge" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="职业" prop="patientProfession">
          <el-input v-model="form.patientProfession" placeholder="请输入职业" />
        </el-form-item>
        <el-form-item label="民族" prop="nation">
          <el-input v-model="form.nation" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="身高" prop="patientHeight">
          <el-input v-model="form.patientHeight" placeholder="请输入身高" />
        </el-form-item>
        <el-form-item label="体重" prop="patientWeight">
          <el-input v-model="form.patientWeight" placeholder="请输入体重" />
        </el-form-item>
        <el-form-item label="BMI" prop="patientBmi">
          <el-input v-model="form.patientBmi" placeholder="请输入BMI" />
        </el-form-item>
        <el-form-item label="联系方式" prop="phoneNo">
          <el-input v-model="form.phoneNo" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="付费方式" prop="payWay">
          <el-input v-model="form.payWay" placeholder="请输入付费方式" />
        </el-form-item>
        <el-form-item label="数据来源" prop="sourceInfo">
          <el-input v-model="form.sourceInfo" placeholder="请输入数据来源" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <router-view> </router-view>
  </div>
</template>

<script>
import {
  listBaseInfo,
  getBaseInfo,
  delBaseInfo,
  addBaseInfo,
  updateBaseInfo,
} from "@/api/workstation/baseInfo";
import {
  listUser,
  getUser,
  delUser,
  addUser,
  updateUser,
  resetUserPwd,
  changeUserStatus,
  deptTreeSelect,
  deptList,
} from "@/api/system/user";
import { getDicts } from "@/api/system/dict/data";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "BaseInfo",
  components: { Treeselect },
  data() {
    return {
      setDisabled: {
        // 返回禁用时间
        disabledDate(time) {
          return time.getTime() > Date.now(); // 可选历史天、可选当前天、不可选未来天
          // return time.getTime() > Date.now() - 8.64e7;  // 可选历史天、不可选当前天、不可选未来天
          // return time.getTime() < Date.now() - 8.64e7;  // 不可选历史天、可选当前天、可选未来天
          // return time.getTime() < Date.now(); // 不可选历史天、不可选当前天、可选未来天
        },
      },
      // 部门树选项
      deptOptions: [],
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 患者基本信息表格数据
      baseInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        doctorName: undefined, // 住院医师的名字  搜索
        medicareNo: undefined,
        patientName: undefined,
        // medicalRecordNo: undefined,
        patientNo: undefined,
        deptId: undefined,
        // admissionDate: undefined,
        admissionTime: undefined,
        doctorId: undefined,
        bedNo: undefined,
        firstDiagnose: undefined,
        guardianLevel: undefined,
        patientState: undefined,
        patientSex: undefined,
        patientAge: undefined,
        patientProfession: undefined,
        nation: undefined,
        patientHeight: undefined,
        patientWeight: undefined,
        patientBmi: undefined,
        phoneNo: undefined,
        payWay: undefined,
        sourceInfo: undefined,
        params: {},
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [{ required: true, message: "患者ID不能为空", trigger: "blur" }],
        patientName: [
          { required: true, message: "患者姓名不能为空", trigger: "blur" },
        ],
        medicalRecordNo: [
          { required: true, message: "病案号不能为空", trigger: "blur" },
        ],
        patientNo: [
          { required: true, message: "ID号不能为空", trigger: "blur" },
        ],
        deptId: [
          { required: true, message: "科室/病区不能为空", trigger: "blur" },
        ],
        admissionTime: [
          { required: true, message: "入院时间不能为空", trigger: "blur" },
        ],
        doctorId: [
          { required: true, message: "临床药师不能为空", trigger: "blur" },
        ],
        bedNo: [{ required: true, message: "床号不能为空", trigger: "blur" }],
        firstDiagnose: [
          { required: true, message: "第一诊断不能为空", trigger: "blur" },
        ],
        guardianLevel: [
          { required: true, message: "监护分级不能为空", trigger: "blur" },
        ],
        patientState: [
          { required: true, message: "住院状态不能为空", trigger: "blur" },
        ],
        patientSex: [
          { required: true, message: "患者性别不能为空", trigger: "change" },
        ],
        patientAge: [
          { required: true, message: "年龄不能为空", trigger: "blur" },
        ],
        patientProfession: [
          { required: true, message: "职业不能为空", trigger: "blur" },
        ],
        nation: [{ required: true, message: "民族不能为空", trigger: "blur" }],
        patientHeight: [
          { required: true, message: "身高不能为空", trigger: "blur" },
        ],
        patientWeight: [
          { required: true, message: "体重不能为空", trigger: "blur" },
        ],
        patientBmi: [
          { required: true, message: "BMI不能为空", trigger: "blur" },
        ],
        phoneNo: [
          { required: true, message: "联系方式不能为空", trigger: "blur" },
        ],
        payWay: [
          { required: true, message: "付费方式不能为空", trigger: "blur" },
        ],
        sourceInfo: [
          { required: true, message: "数据来源不能为空", trigger: "blur" },
        ],
      },
      guardianLevel: [], // 监护分级
      patientState: [], // 住院状态
      userSex: [], // 患者性别
      payWay: [], // 付费方式
      sourceInfo: [], // 患者信息来源
      DoctorList: [], // 对应科室的医生列表
      msg: {}, // 患者管理页搜索条件
      time: "", // 起始日期
    };
  },
  computed: {
    role() {
      return this.$store.state.user.roles;
    },
    useInfo() {
      return this.$store.state.user.user;
    },
    info() {
      return this.$store.state.user.search;
    },
  },
  created() {
    // // 回显搜索条件
    // if (this.$route.query.info && typeof this.$route.query.info !== "string") {
    //   this.queryParams = this.$route.query.info;
    //   console.log(this.queryParams);
    // }
    this.queryParams = this.info;
    console.log(this.info, 666666666666);
    this.getDeptTree();
    this.getList();
    // 查询所有的医生 过滤掉管理员
    listUser().then((response) => {
      // console.log(response.rows);
      // console.log(this.role);
      if (this.role.length == 1 && this.role[0] == "doctor") {
        console.log(this.useInfo);
        // this.form.doctorId = this.useInfo.userId
        this.DoctorList = [
          {
            nickName: this.useInfo.userName,
            userId: this.useInfo.userId,
          },
        ];
        return;
      }
      this.DoctorList = response.rows.filter((item) => {
        return item.userName !== "admin";
      });
    });
    // 字典查询  监护分级
    getDicts("guardian_level").then((res) => {
      // console.log(res.data);
      this.guardianLevel = res.data;
    });
    // 字典查询  住院状态
    getDicts("patient_state").then((res) => {
      // console.log(res.data);
      this.patientState = res.data;
    });
    // 字典查询  患者性别
    getDicts("sys_user_sex").then((res) => {
      // console.log(res.data);
      this.userSex = res.data;
    });
    // 字典查询  付费方式
    getDicts("pay_way").then((res) => {
      // console.log(res.data);
      this.payWay = res.data;
    });
    // 字典查询  患者信息来源
    getDicts("source_info").then((res) => {
      // console.log(res.data);
      this.sourceInfo = res.data;
    });
  },
  // watch: {
  //   $route: {
  //     // $route可以用引号，也可以不用引号  监听的对象
  //     handler(to, from) {
  //       console.log("路由变化了");
  //       console.log("当前页面路由：" + to);
  //       console.log("上一个路由：" + from);
  //     },
  //     deep: true, // 深度观察监听 设置为 true
  //     immediate: true, // 第一次初始化渲染就可以监听到
  //   },
  // },
  methods: {
    handletime(val) {
      console.log(val);
      if (val) {
        this.queryParams.params = {};
        this.queryParams.params["beginDate"] = val[0];
        this.queryParams.params["endDate"] = val[1];
        console.log(this.queryParams);
      } else {
        this.queryParams.params = {};
      }
    },
    // 去患者详情页
    toUseDetail(item) {
      this.$store.commit("SET_SEARCH", this.queryParams);
      // 打开新窗口
      window.open(
        `/detail?id=${item.id}&medicalRecodeNo=${item.medicalRecordNo}`
      );
      // this.$router.push({
      //   path: "/detail",
      //   query: {
      //     id: item.id,
      //     medicalRecodeNo: item.medicalRecordNo,
      //     // info: this.queryParams, // 记录搜索条件
      //   },
      // });
    },
    /** 查询科室下拉树结构 */
    getDeptTree() {
      console.log(this.role, this.useInfo);
      // 质控员 拥有所有科室
      if (this.role.includes("quality")) {
        deptTreeSelect().then((response) => {
          this.deptOptions = response.data;
        });
        return;
      }
      console.log("用户信息", this.useInfo);
      // 指定了常驻病区 下拉查询
      if (this.useInfo.longDept) {
        let params = {};
        params.params = {};
        params.params["longDept"] = this.useInfo.longDept;
        deptList(params).then((response) => {
          // this.deptOptions = response.data;
          let arr = [];
          response?.data.forEach((item) => {
            let obj = {
              id: item.deptId,
              label: item.deptName,
              parentId: item.parentId,
            };
            arr.push(obj);
          });
          this.deptOptions = arr;
        });
      } else {
        // 指定了科室  没有指定病区
        let params = {
          parentId: this.useInfo.deptId,
        };
        deptList(params).then((response) => {
          // this.deptOptions = response.data;
          let arr = [];
          response?.data.forEach((item) => {
            let obj = {
              id: item.deptId,
              label: item.deptName,
              parentId: item.parentId,
            };
            arr.push(obj);
          });
          this.deptOptions = arr;
        });
      }
    },
    /** 查询患者基本信息列表 */
    getList() {
      this.loading = true;
      listBaseInfo(this.queryParams).then((response) => {
        this.baseInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        patientName: undefined,
        medicalRecordNo: undefined,
        patientNo: undefined,
        deptId: undefined,
        admissionDate: undefined,
        doctorId: undefined,
        bedNo: undefined,
        firstDiagnose: undefined,
        guardianLevel: undefined,
        patientState: undefined,
        patientSex: undefined,
        patientAge: undefined,
        patientProfession: undefined,
        nation: undefined,
        patientHeight: undefined,
        patientWeight: undefined,
        patientBmi: undefined,
        phoneNo: undefined,
        payWay: undefined,
        sourceInfo: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        patientName: undefined,
        medicalRecordNo: undefined,
        patientNo: undefined,
        deptId: undefined,
        // admissionDate: undefined,
        admissionTime: undefined,
        doctorId: undefined,
        bedNo: undefined,
        firstDiagnose: undefined,
        guardianLevel: undefined,
        patientState: undefined,
        patientSex: undefined,
        patientAge: undefined,
        patientProfession: undefined,
        nation: undefined,
        patientHeight: undefined,
        patientWeight: undefined,
        patientBmi: undefined,
        phoneNo: undefined,
        payWay: undefined,
        sourceInfo: undefined,
        params: {},
      };
      this.time = "";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加患者基本信息";
    },
    handleDoctorName(val) {
      let person = this.DoctorList.filter((item) => {
        return item.userId == val;
      });
      this.form.doctorName = person[0].nickName;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getBaseInfo(id).then((response) => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改患者基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateBaseInfo(this.form)
              .then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            this.form.sourceInfo = "0"; // 代表是手工录入
            addBaseInfo(this.form)
              .then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除患者基本信息编号为"' + ids + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delBaseInfo(ids);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "workstation/baseInfo/export",
        {
          ...this.queryParams,
        },
        `baseInfo_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style scoped lang="scss">
// 一级护理
.one {
  background-color: #f9d9dd !important;
}

// 二级护理
.two {
  background-color: #fef0df !important;
}

// 出院患者
.useLeaveStatus {
  display: inline-block;
  text-align: center;
  line-height: 36px;
  width: 73px;
  height: 36px;
  background-color: rgba(245, 154, 35, 1);
  font-size: 14px;
  color: #ffffff;
}

.mainInfoBox {
  // display: grid;
  // /* 声明列的宽度,数字3表示的重复3次，即有3列宽度为200px*/
  // grid-template-columns: repeat(5, 300px);
  // /* 声明行间距和列间距 */
  // grid-gap: 20px;
  // /* 分别表示两行的高度 */
  // grid-template-rows: 320px;
  .userBox {
    margin-top: 10px;
    padding: 10px 10px 10px 20px;
    width: 315px;
    height: 355px;
    box-sizing: border-box;
    background-color: #e9f4d8;

    .line {
      margin-top: 10px;
      display: flex;
      align-items: center;

      // 住院患者
      .useStatus {
        display: inline-block;
        text-align: center;
        line-height: 36px;
        width: 73px;
        height: 36px;
        background-color: rgba(112, 182, 3, 1);
        font-size: 14px;
        color: #ffffff;
      }

      .title {
        display: inline-block;
        width: 70px !important;
        font-family: "PingFang SC ", "PingFang SC", sans-serif;
        font-weight: 400;
        font-style: normal;
        font-size: 14px;
        color: #86909c;
      }

      .titleNum {
        // display: inline-block;
        width: 220px !important;
        margin-left: 5px;
        font-family: "PingFang SC ", "PingFang SC", sans-serif;
        font-weight: 400;
        font-style: normal;
        font-size: 14px;
        color: #1d2129;
      }
    }
  }
}
</style>
